<?php
/**
 * The control file of blog module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class sysmanage extends control
{
	private $_network;
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->app->loadLang('index');
        $this->_network=$this->app->loadClass('network');
        if(!isset($_SESSION['username'])){
          $this->locate($this->createLink('index','login'));
        }
		//$this->_uploadfile=$this->app->loadClass('uploadfile');
		
    }
    
    /**
     * 用户管理
     * @access public
     * @return void
     */
    public function userconf($recTotal = 0, $recPerPage = 20, $pageID = 0)
    {
    	//动态加载css
    	$this->view->cssload =array('theme/default/css/report_alarm_fault.css',
    	                             'theme/default/css/style/cupertino/jquery-ui-1.7.2.custom.css');
    	$this->view->jsload=array('scripts/jquery-ui-1.7.2.custom.min.js',
    	                          'scripts/timepicker.js',
    	                           'boot-popover.js' 
    	                           );
        $this->app->loadClass('pager');
        $pager = new pager($recTotal, $recPerPage, $pageID);
        $this->view->title    = '用户管理-IPv6网站升级';
        $this->view->user_info_list = $this->sysmanage->get_user_info($pager);
        $this->view->pager    = $pager;
        $this->display();
    }
    /**
     * 显示添加用户表单信息
     */
    public function add_user(){
    	
      $this->display();
    }
    /**
     * 处理添加用户信息
     */
    public function done_add_user(){
    	$this->sysmanage->set_optlog('添加用户');
       if(!empty($_POST))
        {
            $id = $this->sysmanage->create_user_info();
            if(dao::isError()||$id==false){
               echo 'failure';
            }else{
               echo 'success';
            }
        }
    }
    /**
     * 初始化用户密码为123456
     */
    public function reset_pwd(){
       $this->sysmanage->set_optlog('初始化用户密码'.$_POST['userid']);
       if(!empty($_POST['userid']))
        {
        	$data=new stdClass();
        	$data->pwd=md5(123456);
            $id = $this->sysmanage->update_user_info($data,$_POST['userid']);
            if(dao::isError()){
               echo 'failure';
            }else{
               echo 'success';
            }
        }
    }
    /**
     * 改变用户状态
     */
    public function change_user_status(){
    	$this->sysmanage->set_optlog('改变用户状态'.$_POST['userid']);
        if(!empty($_POST['userid']))
        {
        	
        	$data=new stdClass();
        	$data->status=$_POST['status'];
            $id = $this->sysmanage->update_user_info($data,$_POST['userid']);
            if(dao::isError()){
               echo 'failure';
            }else{
               echo 'success';
            }
        }
    }
   /**
      * 删除用户信息
      */
     public function del_user_info(){
     	$this->sysmanage->set_optlog('删除用户信息'.$_POST['userid']);
        if(!empty($_POST['userid']))
        {
            $id = $this->sysmanage->delete_user_info($_POST['userid']);
            if(dao::isError()){
               echo 'failure';
            }else{
               echo 'success';
            }
        }
     }
  
/**
      * 设置系统时间
      */
     public function  set_systime(){
     	$this->sysmanage->set_optlog('设置系统时间');
     	$computer_time=$_POST['computer_time'];
     	shell_exec('date -s "'.$computer_time.'"');
        echo "success";
     }
    
     
    /**
      * 系统日志
      */
     public function sysoptlog($recTotal = 0, $recPerPage = 20, $pageID = 0,$datetime_start='',$datetime_end='',$key_word=''){
		$this->view->title    = '系统日志-IPv6网站升级';
     	$this->view->cssload =array('theme/default/css/report_alarm_fault.css',
    	                             'theme/default/css/style/cupertino/jquery-ui-1.7.2.custom.css');
    	$this->view->jsload=array('scripts/jquery-ui-1.7.2.custom.min.js',
    	                          'scripts/timepicker.js',
    	                           'boot-popover.js' 
    	                           );
    	$pageJS .= <<<EOT
			var datatime_display = false;
			var settings = {
			    duration: '',
			    showTime: true,
			    constrainInput: false,
			    time24h: true,
			    closeText: '确定',
			    prevText: '上个月',
			    nextText: '下个月',
			    currentText: '今天',
			    dateFormat: 'yy-mm-dd',
			    firstDay: 1,
			    dayNamesMin: ['天', '一', '二', '三', '四', '五', '六'],
			    monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月', ]
			}
			$(function() {
			    $('#datetime_start').datepicker(settings);
			    $('#datetime_end').datepicker(settings);
			});
EOT;
    	$this->view->pageJS=$pageJS;     
        $this->app->loadClass('pager');
        $pager = new pager($recTotal, $recPerPage, $pageID);
        
        $where=new stdClass();
        $where->datetime_start=$datetime_start;
        $where->datetime_end=$datetime_end;
        $where->key_word=$key_word;
        
        $this->view->oplog_list = $this->sysmanage->get_optlog($pager,$where);
        $this->view->pager    = $pager;
        $this->display();
     }
     
  /**
     * 我的信息
     * @access public
     * @return void
     */
    public function myinfo()
    {
    	//动态加载css
    	$this->view->cssload =array('theme/default/css/report_alarm_fault.css',
    	                             'theme/default/css/style/cupertino/jquery-ui-1.7.2.custom.css');
    	$this->view->jsload=array('scripts/jquery-ui-1.7.2.custom.min.js');
		$this->view->title    = '我的信息-IPv6网站升级';
        
        $this->display();
    }
    /**
     * 更新密码
     */
    public function update_pwd(){
    	$this->sysmanage->set_optlog('更新密码'.$_POST['username']);
    	$username=$_POST['username'];
    	$pwd_old=$_POST['pwd_old'];
    	$pwd_new=$_POST['pwd_new'];
    	
        $flag=$this->sysmanage->is_user_exist($username,$pwd_old);
        if(!$flag){
        	echo 'old_error';
        }else{
        	$data=new stdClass();
        	$data->pwd=md5($_POST['pwd_new']);
            $id = $this->sysmanage->update_user_info($data,$_SESSION['userid']);
            if(dao::isError()){
               echo 'failure';
            }else{
               echo 'success';
            }
        }
    }
    /**********************************************************************************/
  
}
